<template>
	<view>
		<view class="" style="text-align: center;margin-top: 30rpx;">
			应缴纳保证金
		</view>
		<view class=""
			style="text-align: center;font-size: 60rpx;font-weight: 600;margin: 60rpx 0;margin-top: 30rpx;color: #ff1414;">
			{{money.toFixed(2)}}
		</view>
		<view class="btn" @click="jn">
			补缴保证金
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: 0,
			}
		},
		onLoad(opt) {
			this.money = Number(opt.money)
		},
		methods: {
			jn() {
				if (true) {
					this.disabled = true;
					uni.showLoading({
						mask: true
					})
					uni.login({
						success: (e) => {
							this.wanlPay(e.code);
						},
						fail: (e) => {
							uni.showModal({
								content: "无法获取微信code,原因为: " + e.errMsg,
								showCancel: false
							})
						}
					})
				}
			},
			async wanlPay(code) {
				let that = this;
				await uni.request({
					url: '/wanlshop/pay/rechargeSubmit',
					method: 'POST',
					data: {
						type: "wechat",
						method: "miniapp",
						code: code,
						money: this.money
					},
					header: {
						isAdmin: true,
						token: uni.getStorageSync("shop_login_token")
					},
					success: res => {
						uni.hideLoading()
						uni.requestPayment({
							appId: res.data.appId,
							nonceStr: res.data.nonceStr,
							package: res.data.package,
							paySign: res.data.paySign,
							signType: res.data.signType,
							timeStamp: res.data.timeStamp,
							success: async (e) => {
								uni.navigateBack()
							},
							fail: (e) => {
								uni.showModal({
									content: "支付失败",
									showCancel: false
								})
							},
							complete: () => {
								uni.hideLoading()
								that.disabled = false;
							}
						})
					}
				});

			},
		}
	}
</script>

<style scoped lang="scss">
	.btn {
		background-color: black;
		color: white;
		text-align: center;
		padding: 30rpx 0;
		border-radius: 100px;
		margin: 30rpx;
		margin-top: 50rpx;
	}
</style>